import React, { useEffect } from 'react'

const Document = ({ title, description, keywords, children }) => {
  useEffect(() => {
    document.title = title
  }, [title])
  useEffect(() => {
    Array.from(document.getElementsByTagName('meta')).forEach(meta => {
      switch (meta.name) {
        case 'description': {
          meta.content = description
          break
        }
        case 'keywords': {
          meta.content = keywords
          break
        }
      }
    })
  }, [description, keywords])
  return children
}

export default Document
